package gdut.imis.controller;

import gdut.imis.Utils.Result;
import gdut.imis.domain.Classes;
import gdut.imis.service.ClassesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author JiaFu
 * @Date 2023/4/7 14:01
 */
@RestController
@RequestMapping("/classes")
@Api(value = "班级档案",tags = {"班级档案"})
@RequiredArgsConstructor
public class ClassesController extends BaseController {

    private final ClassesService classesService;

    @ApiOperation("新增班级档案(拥有classes权限)")
    @PostMapping("/addClass")
    @PreAuthorize("@cp.hasPermission('classes')")
    public Result add(@RequestBody Classes classes){
        return classesService.addClass(classes);
    }

    @ApiOperation("根据专业id查询班级列表")
    @GetMapping("/getClassListByMajorId/{majorId}")
    public Result getClassListByMajorId(@PathVariable("majorId") Long majorId){
        return classesService.getClassListByMajorId(majorId);
    }

    @ApiOperation("根据学生id查询学生班级、专业、班主任、学校信息")
    @GetMapping("/getClassesInfoByStuId/{studentId}")
    public Result getClassesInfoByStuId(@PathVariable("studentId") Long studentId){
        return classesService.getClassesInfoByStuId(studentId);
    }
}
